package org.javabasics.stream;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by LUOLIANG on 2016/10/25.
 * 利用stream计算菲波那切数列
 */
public class FibonacciSupplier implements Supplier<Long> {
    long a = 0;
    long b = 1;

    @Override
    public Long get() {
        long x = a + b;
        a = b;
        b = x;

        return a;
    }


    public static void main(String[] args) {
        Stream<Long> fibonacci = Stream.generate(new FibonacciSupplier());
//        fibonacci.limit(10).forEach(System.out::println);
        List<Long> list = fibonacci.skip(1).limit(10).collect(Collectors.toList());
        list.forEach(System.out::println);
    }
}
